from django.contrib import admin
from goods import models
from celery_tasks.meiduofunc.tasks import generate_static_list_search_html, generate_static_sku_detail_html


# Register your models here.

class GoodsModelAdmin(admin.ModelAdmin):
    list_display = ['name', 'brand', 'sales', 'comments']

    def save_model(self, request, obj, form, change):
        obj.save()
        generate_static_list_search_html.delay()

    def delete_model(self, request, obj):
        obj.save()
        generate_static_list_search_html.delay()


class SKUModelAdmin(admin.ModelAdmin):
    list_display = ['name', 'goods', 'id', 'stock', 'sales']

    def save_model(self, request, obj, form, change):
        obj.save()
        generate_static_sku_detail_html.delay(obj.id)

    def delete_model(self, request, obj):
        obj.save()
        generate_static_sku_detail_html.delay(obj.id)


admin.site.register(models.Goods, GoodsModelAdmin)
admin.site.register(models.SKU, SKUModelAdmin)
admin.site.register(models.SKUImage)
